<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    /*<a name="line.1"></a>
<FONT color="green">002</FONT>     * Copyright (C) 2010 TTPASI, Inc. All Rights Reserved.<a name="line.2"></a>
<FONT color="green">003</FONT>     *<a name="line.3"></a>
<FONT color="green">004</FONT>     * Licensed under the Apache License, Version 2.0 (the "License");<a name="line.4"></a>
<FONT color="green">005</FONT>     * you may not use this file except in compliance with the License.<a name="line.5"></a>
<FONT color="green">006</FONT>     * You may obtain a copy of the License at<a name="line.6"></a>
<FONT color="green">007</FONT>     *<a name="line.7"></a>
<FONT color="green">008</FONT>     *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.8"></a>
<FONT color="green">009</FONT>     *<a name="line.9"></a>
<FONT color="green">010</FONT>     * Unless required by applicable law or agreed to in writing, software<a name="line.10"></a>
<FONT color="green">011</FONT>     * distributed under the License is distributed on an "AS-IS" BASIS,<a name="line.11"></a>
<FONT color="green">012</FONT>     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.12"></a>
<FONT color="green">013</FONT>     * See the License for the specific language governing permissions and<a name="line.13"></a>
<FONT color="green">014</FONT>     * limitations under the License.<a name="line.14"></a>
<FONT color="green">015</FONT>     */<a name="line.15"></a>
<FONT color="green">016</FONT>    <a name="line.16"></a>
<FONT color="green">017</FONT>    package ttpasi.jgenere.initial_port.languagedata;<a name="line.17"></a>
<FONT color="green">018</FONT>    <a name="line.18"></a>
<FONT color="green">019</FONT>    import java.util.Map;<a name="line.19"></a>
<FONT color="green">020</FONT>    <a name="line.20"></a>
<FONT color="green">021</FONT>    import ttpasi.jgenere.initial_port.VigCrack;<a name="line.21"></a>
<FONT color="green">022</FONT>    <a name="line.22"></a>
<FONT color="green">023</FONT>    /**<a name="line.23"></a>
<FONT color="green">024</FONT>     * Java port of language data from PyGenere v 0.3.  See pygenere.py to learn <a name="line.24"></a>
<FONT color="green">025</FONT>     * more about the original PyGenere implementation, including author contact <a name="line.25"></a>
<FONT color="green">026</FONT>     * information and licensing and use terms.<a name="line.26"></a>
<FONT color="green">027</FONT>     * &lt;p/&gt;<a name="line.27"></a>
<FONT color="green">028</FONT>     * Base class for data objects with language alphabet character use statistics. <a name="line.28"></a>
<FONT color="green">029</FONT>     * Used by {@link VigCrack}.<a name="line.29"></a>
<FONT color="green">030</FONT>     * &lt;p/&gt;<a name="line.30"></a>
<FONT color="green">031</FONT>     * Note: This implementation only supports characters in the English alphabet, <a name="line.31"></a>
<FONT color="green">032</FONT>     * though multiple languages are supported.<a name="line.32"></a>
<FONT color="green">033</FONT>     * &lt;p/&gt;<a name="line.33"></a>
<FONT color="green">034</FONT>     * Note: While the cryptography implementations in jgenere.initial_port work <a name="line.34"></a>
<FONT color="green">035</FONT>     * correctly according to the provided test cases, they were not optimized or <a name="line.35"></a>
<FONT color="green">036</FONT>     * otherwise designed to make use of Java language and platform features.  They <a name="line.36"></a>
<FONT color="green">037</FONT>     * are simple ports of the original Python implementation of PyGenere, provided <a name="line.37"></a>
<FONT color="green">038</FONT>     * for academic purposes.  Visit the project web site at <a name="line.38"></a>
<FONT color="green">039</FONT>     * &lt;a target="_blank" href="http://code.google.com/p/jgenere/"&gt;http://code.google.com/p/jgenere/&lt;/a&gt; <a name="line.39"></a>
<FONT color="green">040</FONT>     * for preferred Java-based implementations of these cryptography algorithms.<a name="line.40"></a>
<FONT color="green">041</FONT>     * &lt;p/&gt;<a name="line.41"></a>
<FONT color="green">042</FONT>     * The original PyGenere v 0.3 language data code:<a name="line.42"></a>
<FONT color="green">043</FONT>     * &lt;pre&gt;<a name="line.43"></a>
<FONT color="green">044</FONT>     *   """<a name="line.44"></a>
<FONT color="green">045</FONT>     *   Character frequencies taken from:<a name="line.45"></a>
<FONT color="green">046</FONT>     *   http://www.csm.astate.edu/~rossa/datasec/frequency.html (English)<a name="line.46"></a>
<FONT color="green">047</FONT>     *   http://www.characterfrequency.com/ (French, Italian, Portuguese, Spanish)<a name="line.47"></a>
<FONT color="green">048</FONT>     *   http://www.santacruzpl.org/readyref/files/g-l/ltfrqger.shtml (German)<a name="line.48"></a>
<FONT color="green">049</FONT>     *   """<a name="line.49"></a>
<FONT color="green">050</FONT>     * <a name="line.50"></a>
<FONT color="green">051</FONT>     *   # The following are language-specific data on character frequencies.<a name="line.51"></a>
<FONT color="green">052</FONT>     *   # Kappa is the "index of coincidence" described in the cryptography paper<a name="line.52"></a>
<FONT color="green">053</FONT>     *   # (link above).<a name="line.53"></a>
<FONT color="green">054</FONT>     *   <a name="line.54"></a>
<FONT color="green">055</FONT>     *   __english_data = {<a name="line.55"></a>
<FONT color="green">056</FONT>     *                     'A':8.167, 'B':1.492, 'C':2.782, 'D':4.253, 'E':12.702,<a name="line.56"></a>
<FONT color="green">057</FONT>     *                     'F':2.228, 'G':2.015, 'H':6.094, 'I':6.996, 'J':0.153,<a name="line.57"></a>
<FONT color="green">058</FONT>     *                     'K':0.772, 'L':4.025, 'M':2.406, 'N':6.749, 'O':7.507,<a name="line.58"></a>
<FONT color="green">059</FONT>     *                     'P':1.929, 'Q':0.095, 'R':5.987, 'S':6.327, 'T':9.056,<a name="line.59"></a>
<FONT color="green">060</FONT>     *                     'U':2.758, 'V':0.978, 'W':2.360, 'X':0.150, 'Y':1.974,<a name="line.60"></a>
<FONT color="green">061</FONT>     *                     'Z':0.074, 'max_val':12.702, 'kappa':0.0667<a name="line.61"></a>
<FONT color="green">062</FONT>     *                    }<a name="line.62"></a>
<FONT color="green">063</FONT>     *<a name="line.63"></a>
<FONT color="green">064</FONT>     *   __french_data = {<a name="line.64"></a>
<FONT color="green">065</FONT>     *                    'A':8.11, 'B':0.903, 'C':3.49, 'D':4.27, 'E':17.22,<a name="line.65"></a>
<FONT color="green">066</FONT>     *                    'F':1.14, 'G':1.09, 'H':0.769, 'I':7.44, 'J':0.339,<a name="line.66"></a>
<FONT color="green">067</FONT>     *                    'K':0.097, 'L':5.53, 'M':2.89, 'N':7.46, 'O':5.38,<a name="line.67"></a>
<FONT color="green">068</FONT>     *                    'P':3.02, 'Q':0.999, 'R':7.05, 'S':8.04, 'T':6.99,<a name="line.68"></a>
<FONT color="green">069</FONT>     *                    'U':5.65, 'V':1.30, 'W':0.039, 'X':0.435, 'Y':0.271,<a name="line.69"></a>
<FONT color="green">070</FONT>     *                    'Z':0.098, 'max_val':17.22, 'kappa':0.0746<a name="line.70"></a>
<FONT color="green">071</FONT>     *                   }<a name="line.71"></a>
<FONT color="green">072</FONT>     * <a name="line.72"></a>
<FONT color="green">073</FONT>     *   __german_data = {<a name="line.73"></a>
<FONT color="green">074</FONT>     *                    'A':6.506, 'B':2.566, 'C':2.837, 'D':5.414, 'E':16.693,<a name="line.74"></a>
<FONT color="green">075</FONT>     *                    'F':2.044, 'G':3.647, 'H':4.064, 'I':7.812, 'J':0.191,<a name="line.75"></a>
<FONT color="green">076</FONT>     *                    'K':1.879, 'L':2.825, 'M':3.005, 'N':9.905, 'O':2.285,<a name="line.76"></a>
<FONT color="green">077</FONT>     *                    'P':0.944, 'Q':0.055, 'R':6.539, 'S':6.765, 'T':6.742,<a name="line.77"></a>
<FONT color="green">078</FONT>     *                    'U':3.703, 'V':1.069, 'W':1.396, 'X':0.022, 'Y':0.032,<a name="line.78"></a>
<FONT color="green">079</FONT>     *                    'Z':1.002, 'max_val':16.693, 'kappa':0.0767<a name="line.79"></a>
<FONT color="green">080</FONT>     *                   }<a name="line.80"></a>
<FONT color="green">081</FONT>     * <a name="line.81"></a>
<FONT color="green">082</FONT>     *   __italian_data = {<a name="line.82"></a>
<FONT color="green">083</FONT>     *                     'A':11.30, 'B':0.975, 'C':4.35, 'D':3.80, 'E':11.24,<a name="line.83"></a>
<FONT color="green">084</FONT>     *                     'F':1.09, 'G':1.73, 'H':1.02, 'I':11.57, 'J':0.035,<a name="line.84"></a>
<FONT color="green">085</FONT>     *                     'K':0.078, 'L':6.40, 'M':2.66, 'N':7.29, 'O':9.11,<a name="line.85"></a>
<FONT color="green">086</FONT>     *                     'P':2.89, 'Q':0.391, 'R':6.68, 'S':5.11, 'T':6.76,<a name="line.86"></a>
<FONT color="green">087</FONT>     *                     'U':3.18, 'V':1.52, 'W':0.00, 'X':0.024, 'Y':0.048,<a name="line.87"></a>
<FONT color="green">088</FONT>     *                     'Z':0.958, 'max_val':11.57, 'kappa':0.0733<a name="line.88"></a>
<FONT color="green">089</FONT>     *                    }<a name="line.89"></a>
<FONT color="green">090</FONT>     * <a name="line.90"></a>
<FONT color="green">091</FONT>     *   __portuguese_data = {<a name="line.91"></a>
<FONT color="green">092</FONT>     *                        'A':13.89, 'B':0.980, 'C':4.18, 'D':5.24, 'E':12.72,<a name="line.92"></a>
<FONT color="green">093</FONT>     *                        'F':1.01, 'G':1.17, 'H':0.905, 'I':6.70, 'J':0.317,<a name="line.93"></a>
<FONT color="green">094</FONT>     *                        'K':0.0174, 'L':2.76, 'M':4.54, 'N':5.37, 'O':10.90,<a name="line.94"></a>
<FONT color="green">095</FONT>     *                        'P':2.74, 'Q':1.06, 'R':6.67, 'S':7.90, 'T':4.63,<a name="line.95"></a>
<FONT color="green">096</FONT>     *                        'U':4.05, 'V':1.55, 'W':0.0104, 'X':0.272, 'Y':0.0165,<a name="line.96"></a>
<FONT color="green">097</FONT>     *                        'Z':0.400, 'max_val':13.89, 'kappa':0.0745<a name="line.97"></a>
<FONT color="green">098</FONT>     *                       }<a name="line.98"></a>
<FONT color="green">099</FONT>     * <a name="line.99"></a>
<FONT color="green">100</FONT>     *   __spanish_data = {<a name="line.100"></a>
<FONT color="green">101</FONT>     *                     'A':12.09, 'B':1.21, 'C':4.20, 'D':4.65, 'E':13.89,<a name="line.101"></a>
<FONT color="green">102</FONT>     *                     'F':0.642, 'G':1.11, 'H':1.13, 'I':6.38, 'J':0.461,<a name="line.102"></a>
<FONT color="green">103</FONT>     *                     'K':0.038, 'L':5.19, 'M':2.86, 'N':7.23, 'O':9.58,<a name="line.103"></a>
<FONT color="green">104</FONT>     *                     'P':2.74, 'Q':1.37, 'R':6.14, 'S':7.43, 'T':4.49,<a name="line.104"></a>
<FONT color="green">105</FONT>     *                     'U':4.53, 'V':1.05, 'W':0.011, 'X':0.124, 'Y':1.14,<a name="line.105"></a>
<FONT color="green">106</FONT>     *                     'Z':0.324, 'max_val':13.89, 'kappa':0.0766<a name="line.106"></a>
<FONT color="green">107</FONT>     *                    }<a name="line.107"></a>
<FONT color="green">108</FONT>     * &lt;/pre&gt;<a name="line.108"></a>
<FONT color="green">109</FONT>     * <a name="line.109"></a>
<FONT color="green">110</FONT>     * @author  Bruce [com.gmail @ ProgrammerBruce]<a name="line.110"></a>
<FONT color="green">111</FONT>     * @version 2010.1105<a name="line.111"></a>
<FONT color="green">112</FONT>     */<a name="line.112"></a>
<FONT color="green">113</FONT>    public abstract class LanguageData<a name="line.113"></a>
<FONT color="green">114</FONT>    {<a name="line.114"></a>
<FONT color="green">115</FONT>      public final Map&lt;Character, Double&gt; _frequencies;<a name="line.115"></a>
<FONT color="green">116</FONT>      public final double _max_value;<a name="line.116"></a>
<FONT color="green">117</FONT>      public final double _kappa;<a name="line.117"></a>
<FONT color="green">118</FONT>    <a name="line.118"></a>
<FONT color="green">119</FONT>      LanguageData(Map&lt;Character, Double&gt; frequencies, double max_value, double kappa)<a name="line.119"></a>
<FONT color="green">120</FONT>      {<a name="line.120"></a>
<FONT color="green">121</FONT>        this._frequencies = frequencies;<a name="line.121"></a>
<FONT color="green">122</FONT>        this._max_value = max_value;<a name="line.122"></a>
<FONT color="green">123</FONT>        this._kappa = kappa;<a name="line.123"></a>
<FONT color="green">124</FONT>      }<a name="line.124"></a>
<FONT color="green">125</FONT>    <a name="line.125"></a>
<FONT color="green">126</FONT>      /**<a name="line.126"></a>
<FONT color="green">127</FONT>       * Returns a LanguageData object with language specific alphabet character use <a name="line.127"></a>
<FONT color="green">128</FONT>       * statistics, used by VigCrack.<a name="line.128"></a>
<FONT color="green">129</FONT>       * &lt;p/&gt;<a name="line.129"></a>
<FONT color="green">130</FONT>       * &lt;code&gt;language&lt;/code&gt; is a two character String that indicates which <a name="line.130"></a>
<FONT color="green">131</FONT>       * language to use. Possible values for &lt;code&gt;language&lt;/code&gt; include:<a name="line.131"></a>
<FONT color="green">132</FONT>       * &lt;ul&gt;<a name="line.132"></a>
<FONT color="green">133</FONT>       * &lt;li&gt;EN - for English&lt;/li&gt;<a name="line.133"></a>
<FONT color="green">134</FONT>       * &lt;li&gt;DE - for German&lt;/li&gt;<a name="line.134"></a>
<FONT color="green">135</FONT>       * &lt;li&gt;ES - for Spanish&lt;/li&gt;<a name="line.135"></a>
<FONT color="green">136</FONT>       * &lt;li&gt;FR - for French&lt;/li&gt;<a name="line.136"></a>
<FONT color="green">137</FONT>       * &lt;li&gt;IT - for Italian&lt;/li&gt;<a name="line.137"></a>
<FONT color="green">138</FONT>       * &lt;li&gt;PT - for Portuguese&lt;/li&gt;<a name="line.138"></a>
<FONT color="green">139</FONT>       * &lt;/ul&gt;<a name="line.139"></a>
<FONT color="green">140</FONT>       * <a name="line.140"></a>
<FONT color="green">141</FONT>       * @param language The language for which data is wanted.<a name="line.141"></a>
<FONT color="green">142</FONT>       */<a name="line.142"></a>
<FONT color="green">143</FONT>      public static LanguageData getData(String language)<a name="line.143"></a>
<FONT color="green">144</FONT>      {<a name="line.144"></a>
<FONT color="green">145</FONT>        if (language.equals("DE"))<a name="line.145"></a>
<FONT color="green">146</FONT>          return new GermanData();<a name="line.146"></a>
<FONT color="green">147</FONT>        else if (language.equals("ES"))<a name="line.147"></a>
<FONT color="green">148</FONT>          return new SpanishData();<a name="line.148"></a>
<FONT color="green">149</FONT>        else if (language.equals("FR"))<a name="line.149"></a>
<FONT color="green">150</FONT>          return new FrenchData();<a name="line.150"></a>
<FONT color="green">151</FONT>        else if (language.equals("IT"))<a name="line.151"></a>
<FONT color="green">152</FONT>          return new ItalianData();<a name="line.152"></a>
<FONT color="green">153</FONT>        else if (language.equals("PT"))<a name="line.153"></a>
<FONT color="green">154</FONT>          return new PortugueseData();<a name="line.154"></a>
<FONT color="green">155</FONT>        else<a name="line.155"></a>
<FONT color="green">156</FONT>          return new EnglishData();<a name="line.156"></a>
<FONT color="green">157</FONT>      }<a name="line.157"></a>
<FONT color="green">158</FONT>    }<a name="line.158"></a>




























































</PRE>
</BODY>
</HTML>
